package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.android.log.Log;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.DSTData;

import java.util.List;

/**
 * Created by yanghaojie on 16/7/27.
 */
public class DSTImpl implements DSTDao {
    @Override
    public DSTData find() {
        List<DSTData> dstDataList = DbHelp.getQueryAll(DSTData.class);
        if (dstDataList.size() > 0) {
            return dstDataList.get(0);
        } else {
            return null;
        }
    }

    @Override
    public void add(DSTData dstData) {
        DbHelp.insert(dstData);
    }

    @Override
    public void update(DSTData dstData) {
        List<DSTData> list = DbHelp.getQueryAll(DSTData.class);
        if (null == list || list.size() == 0) {
            DbHelp.insert(dstData);
            Log.e("SocketClient", " 插入");
        } else {
            DSTData data = list.get(0);
            data.setEnd(dstData.getEnd());
            data.setBegin(dstData.getBegin());
            data.setEnable(dstData.getEnable());
            DbHelp.update(data);
            Log.e("SocketClient", "更新");
        }
    }

    @Override
    public void delete() {
        DbHelp.deleteAll(DSTData.class);
    }
}

